package com.dmxh.controller;

import com.dmxh.params.QueryParams;
import com.dmxh.result.PageList;
import com.dmxh.result.Result;
import com.dmxh.service.ContentItemService;
import com.dmxh.vo.ContentCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/contentItem")
public class ContentItemController {

    @Autowired
    private ContentItemService contentItemService;


    @PostMapping("/queryPage")
    public Result queryPage(@RequestBody QueryParams queryParams) {
        PageList<ContentCategoryVo> pageList = contentItemService.queryPage(queryParams);
        return Result.ok().setData(pageList);
    }

    @GetMapping("/getAllContentItem")
    public Result getAllContentItem() {
        List<ContentCategoryVo> list = contentItemService.getAllContentItem();
        return Result.ok().setData(list);
    }

    @PostMapping("/save")
    public Result save(@RequestBody ContentCategoryVo contentCategoryVo) {
        if (contentCategoryVo.getId() == null) {
            contentItemService.addInfo(contentCategoryVo);
        } else {
            contentItemService.updateInfo(contentCategoryVo);
        }
        return Result.ok();
    }
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id")long id) {
        contentItemService.deleteById(id);
        return Result.ok();
    }

    @PatchMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody Integer[]ids) {
        contentItemService.deleteBatch(ids);
        return Result.ok();
    }
}
